package com.jsfcomponent.util;

import javax.faces.event.ActionEvent;
/**
 * Helper class for working with JSF and Facelets
 * @author gbugaj
 *
 */
public class FacesUtil {
	/**
	 * Called for components that accept f:attribute like commandLink or commandButton
	 * example:
	 *  <h:commandLink value="Click here" actionListener="#{myBean.action}">
	        <f:attribute name="attributeName1" value="attributeValue1" />
	        <f:attribute name="attributeName2" value="attributeValue2" />
    	</h:commandLink>
	 * @param event JSF Event
	 * @param name of the attribute we want to get
	 * @return
	 */
	public static String getActionAttribute(ActionEvent event, String name) {
		Object obj=event.getComponent().getAttributes().get(name);		
		if(obj==null){
			throw new IllegalArgumentException("Attribute '"+name+"' dosen't exist");
		}
        return obj.toString();
    }
}
